function triangle(){
  console.log("func triangle 作业1");
  for(i = 0; i < this.n; i++){
  let output = [];
  for(j = 0; j < i + 1; j++){
    output += this.str;
  }
  console.log(output);
  }
}

function revTriangle(){
  console.log("func revTriangle 作业2");
  for(i = 0; i < this.n; i++){
    let output = [];
    for(j = this.n; j > i; j--){
      output += this.str;
    }
    console.log(output);
  }
}

function revTriangle2(){
  console.log("func revTriangle2 作业4");
  for(i = 0; i < this.n; i+=2){
    let output = [];
    for(j = this.n; j > i; j--){
      output += this.str;
    }
    console.log(output);
  }
}

function triangle2(){
  console.log("func triangle2 作业5");
  //  先打印顶端
  var topOutput = [];
  for(i = 0; i < 7; i++)
  {
    topOutput += " ";
  }
  topOutput += this.str;
  console.log(topOutput);

  var leftSpace = 5;
  var midSpace = 1;
  for(i = 0; i < 6; i++)
  {
    let leftOutput = [];
    let midOutput = [];
    for(let j = 0; j < leftSpace + 1; j++)
    {
      leftOutput += " ";
    }

    for(let k = 0; k < midSpace; k++)
    {
      midOutput += " ";
    }

    let output = leftOutput + this.str + midOutput + this.str;
    console.log(output);

    leftSpace --;
    midSpace += 2;
  }

  let endOutput = [];
  for(i = 0; i < 15; i++)
  {
    endOutput += this.str;
  }
  console.log(endOutput);
}

function PrintChar(str, n){
  //this.for1 = triangle;
  //this.for2 = revTriangle;
  this.str = str;
  this.n = n;
}

PrintChar.prototype.for1 = triangle;
PrintChar.prototype.for2 = revTriangle;
PrintChar.prototype.for3 = triangle2;

var p = new PrintChar("*", 10);
p.for1();
console.log("\n");
p.for2();
console.log("\n");
p.for3();
